<?php

namespace Plugins;

/**
 * Description of Excel
 *
 * @author Administrator
 */
class Excel {

    private $phpexcel;

    public function __construct() {
        $dir = dirname(__FILE__);
        require $dir . '/PHPExcel.php';
        $this->phpexcel = new \PHPExcel();
    }

    /**
     * 返回phpexcel对象
     * @return type
     */
    public function phpexcle() {
        return $this->phpexcel;
    }

    /**
     * 返回默认sheet
     * @return type
     */
    public function getActiveSheet() {
        $phpexcelSheet = $this->phpexcel->getActiveSheet();
        //设置对齐方式
        $phpexcelSheet->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER)->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //设置默认字体大小和格式
        $phpexcelSheet->getDefaultStyle()->getFont()->setSize(10)->setName("微软雅黑");
        //设置第一行字体大小和加粗
        $phpexcelSheet->getStyle("A1:AZ1")->getFont()->setSize(12)->setBold(true);
        //设置默认行高
        $phpexcelSheet->getDefaultRowDimension()->setRowHeight(30);
        return $phpexcelSheet;
    }

    /**
     * 返回创建的PHPexcel IO
     * @param obj $obj excel 对象
     * @param string EXCEL类型
     * @return obj
     */
    public function io($obj, $type) {
        return \PHPExcel_IOFactory::createWriter($obj, $type);
    }

    public function excelRead($inputFileName) {
        $inputFileType = 'Excel5';
        $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
        $objPHPExcel = $objReader->load($inputFileName);
        $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
        var_dump($sheetData);
    }

}
